home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr37
/
satsfaxt.zip
/
CCPUTILS.ZIP
/
CCAPPEND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-30
|
19KB
|
435 lines
/*---------------------------------------------------------------------------*
* CCAPPEND.C *
*---------------------------------------------------------------------------*
* This program allows the user to append the contents of the *
* Connection CoProcessor log queue to an ASCII file, in either a *
* formatted, tab-delimited, or comma-delimited form. Optionally, *
* the user may delete the contents of the log queue after appending, *
* thus allowing the board to operate more efficently. *
* *
* The following source code is intended to assist developers in *
* creating applications whic support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of *
* charge and on an as-is basis. THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* SPECIFICALLY EXCLUDED. This source code may be modified, enhanced, *
* copied and distributed with applications that support CAS on a *
* royalty-free basis. *
*---------------------------------------------------------------------------*
* History: - Intitial release 9/14/89. *
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include <string.h>
#include "cas.h" /* Intel CAS header file. */
#include "parse.h" /* Command line parser header file. */
#include "util.h" /* CAS utilities header file. */
#define SPACE_DELIMIT 1 /* Delimit output with spaces. */
#define TAB_DELIMIT 2 /* Delimit output with tabs. */
#define COMMA_DELIMIT 3 /* Delimit output with commas. */
int DelLog = FALSE; /* Delete log after appending. */
int Tab = FALSE; /* Tab delimited output. */
int Comma = FALSE; /* Comma delimited output. */
int Help = FALSE; /* Show help text. */
int RedirOut = FALSE; /* Redirect output to file. */
ECF *TCFbuffer; /* Task Control File buffer. */
FTR *FTRbuffer; /* File Transfer Record buffer. */
FILE *ccout; /* Redirected stdout file. */
STABLE SwitchTable [] = /* Parser switch table. */
{
{ 'C', BOOL, &DelLog },
{ 'c', BOOL, &DelLog },
{ 'T', BOOL, &Tab },
{ 't', BOOL, &Tab },
{ ',', BOOL, &Comma },
{ 'R', BOOL, &RedirOut },
{ 'r', BOOL, &RedirOut },
{ '?', BOOL, &Help }
};
#define TABLESIZE (sizeof(SwitchTable)/sizeof(STABLE))
char *DescTable[] = /* Help function description table. */
{
"CCAPPEND (V1.0) Appends the contents of the log to the specified \"filename\",\n",
"in ASCII format. If \"filename\" doesn't exist, it is created. \"filename\"\n",
"may include a path (for example, c:\\sales\\record.txt).\n\n",
"The headers from the log file are added to the top of \"filename\".\n\n",
"Syntax: CCAPPEND filename [option...]\n\n"
};
#define DESCSIZE (sizeof(DescTable)/sizeof(DescTable[0]))
char *HelpTable[] = /* Help function text file. */
{
" /C Clear log after appending to log file.\n\n",
" /T Tab delimited log file.\n",
" /, Comma delimited log file.\n\n",
" /R Redirect output to file OUTPUT.CC.\n",
" /? Display help information.\n"
};
#define HELPSIZE (sizeof(HelpTable)/sizeof(HelpTable[0]))
/*---------------------------------------------------------------------------*
* GetTaskBuffer() *
*---------------------------------------------------------------------------*
* Gets information about the event specified by Handle. The task control *
* file is opened and read. The FileHandle returned is a normal MS-DOS *
* file handle. *
*---------------------------------------------------------------------------*
* Parameters: int Handle - The event handle of the task. *
* BYTE Queue - The queue (Receive, Log or Task). *
* char *TCFbuffer - Uninitialized ECS structure. *
* int *FileHandle - Filled with DOS file handle. *
* Return: none *
*---------------------------------------------------------------------------*/
GetTaskBuffer(int Handle, BYTE Queue, char *TCFbuffer, int *FileHandle)
{
/* Let CAS open the Task Control File. Read the contents into TCFbuffer. */
if((*FileHandle = CASOpenFile(Handle,0,Queue)) > 0) {
read(*FileHandle, TCFbuffer, sizeof(ECF));
}
else
CASError(CASNOTCF, TRUE, -(*FileHandle));
}
/*---------------------------------------------------------------------------*
* GetFileTransferBuffer() *
*---------------------------------------------------------------------------*
* Gets information about the file transfer record. Offset specifies the *
* location within the task control file of the FTR record. The offset of *
* the first FTR is stored at offset 10 of the TCF. Each subsequent FTR *
* is 128 bytes after the first. *
*---------------------------------------------------------------------------*
* Parameters: long Offset - File Offset to begin reading. *
* char *FTRbuffer - Uninitialized FTR structure, filled with *
* file transfer record on return. *
* int *FileHandle - DOS file handle of Task Control file. *
* (Returned from call to GetTaskBuffer()). *
* Return: none *
*---------------------------------------------------------------------------*/
GetFileTransferBuffer(long Offset, char *FTRbuffer, int *FileHandle)
{
/* Read the File Transfer Record specified by Offset. */
lseek(*FileHandle, Offset, SEEK_SET);
read(*FileHandle, FTRbuffer, sizeof(FTR));
}
/*---------------------------------------------------------------------------*
* CorrectDate() *
*---------------------------------------------------------------------------*
* Converts a date as stored in a control file to a string that can be *
* displayed on stdout. The TCFbuffer must first be read from the control *
* file. *
*---------------------------------------------------------------------------*
* Parameters: ECF *TCFbuffer - Filled in ECS structure. *
* char string[] - Array to place ascii date string. *
* Return: none *
*---------------------------------------------------------------------------*/
CorrectDate(ECF *TCFbuffer, CAS_DATE *Date, CAS_TIME *Time)
{
Date->Day = TCFbuffer->EventDate & 0x001F;
Date->Month = (TCFbuffer->EventDate & 0x01E0) >> 5;
Date->Year = ((TCFbuffer->EventDate & 0xFE00) >> 9) + 1980;
Time->Minute = (TCFbuffer->EventTime & 0x07E0) >> 5;
Time->Hour = (TCFbuffer->EventTime & 0xF800) >> 11;
}
/*---------------------------------------------------------------------------*
* SpaceIt() *
*---------------------------------------------------------------------------*
* Default output mode. Build the file using spaces as delimiter. *
*---------------------------------------------------------------------------*
* Parameters: FILE *OutFile - Handle of a previously opened file for *
* CCAPPEND output. *
* ECF *TCFbuffer - Structure storing task control info. It must*
* have been filled with task info prior to call. *
* CAS_DATE *Date - Pointer to a date structure. Filled in with *
* call to CorrectDate. *
* CAS_TIME *Time - Pointer to a time structure. Filled in with *
* call to CorrectDate. *
* char action - Array filled in with action string from TCF. *
* char mode - Array filled in with mode string from TCF. *
* char status - Array filled in with status string from TCF. *
* Return: none *
*---------------------------------------------------------------------------*/
SpaceIt(FILE *OutFile, ECF *TCFbuffer, CAS_DATE *Date, CAS_TIME *Time,
char action[], char mode[], char status[])
{
fprintf(OutFile, "%02d/%02d/%2d %-2d:%02d %-8s %-6s", Date->Month,
Date->Day, Date->Year, Time->Hour, Time->Minute, action, mode);
if(TCFbuffer->TransferType < 2)
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, "%7ld", TCFbuffer->TotalPages);
else
fprintf(OutFile, " 0");
else
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, "%7d", TCFbuffer->FilesSent);
else
fprintf(OutFile, " 0");
fprintf(OutFile, " %-8s", status);
fprintf(OutFile," %02d:%02d:%02d", (int)TCFbuffer->ConnectHours,
(int)TCFbuffer->ConnectMinutes,
(int)TCFbuffer->ConnectSeconds);
if((TCFbuffer->EventType == SEND) || (TCFbuffer->EventType == POLLED_SEND))
fprintf(OutFile," %-s\n",TCFbuffer->DestinationName);
else
fprintf(OutFile," %-s\n",TCFbuffer->SenderName);
}
/*---------------------------------------------------------------------------*
* TabIt() *
*---------------------------------------------------------------------------*
* This one builds its output with tabs! *
*---------------------------------------------------------------------------*
* Parameters & Return : See SpaceIt. *
*---------------------------------------------------------------------------*/
TabIt(FILE *OutFile, ECF *TCFbuffer, CAS_DATE *Date, CAS_TIME *Time,
char action[], char mode[], char status[])
{
fprintf(OutFile, "%02d/%02d/%02d\t%-2d:%02d\t%s\t%s", Date->Month,
Date->Day, Date->Year, Time->Hour, Time->Minute, action, mode);
if(TCFbuffer->TransferType < 2)
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, "\t%ld", TCFbuffer->TotalPages);
else
fprintf(OutFile, "\t0");
else
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, "\t%d", TCFbuffer->FilesSent);
else
fprintf(OutFile, "\t0");
fprintf(OutFile, "\t%s",status);
fprintf(OutFile, "\t%02d:%02d:%02d", (int)TCFbuffer->ConnectHours,
(int)TCFbuffer->ConnectMinutes,
(int)TCFbuffer->ConnectSeconds);
if((TCFbuffer->EventType == SEND) || (TCFbuffer->EventType == POLLED_SEND))
fprintf(OutFile, "\t%s\n", TCFbuffer->DestinationName);
else
fprintf(OutFile, "\t%s\n", TCFbuffer->SenderName);
}
/*---------------------------------------------------------------------------*
* CommaIt() *
*---------------------------------------------------------------------------*
* Build the file with commas as the delimiter. *
*---------------------------------------------------------------------------*
* Parameters & Return: See SpaceIt. *
*---------------------------------------------------------------------------*/
CommaIt(FILE *OutFile, ECF *TCFbuffer, CAS_DATE *Date, CAS_TIME *Time,
char action[], char mode[], char status[])
{
fprintf(OutFile, "%02d/%02d/%2d,%-2d:%02d,%s,%s", Date->Month,
Date->Day, Date->Year, Time->Hour, Time->Minute, action, mode);
if(TCFbuffer->TransferType < 2)
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, ",%ld", TCFbuffer->TotalPages);
else
fprintf(OutFile, ",0");
else
if(TCFbuffer->EventStatus == 0)
fprintf(OutFile, ",%d", TCFbuffer->FilesSent);
else
fprintf(OutFile, ",0");
fprintf(OutFile, ",%s",status);
fprintf(OutFile, ",%02d:%02d:%02d", (int)TCFbuffer->ConnectHours,
(int)TCFbuffer->ConnectMinutes,
(int)TCFbuffer->ConnectSeconds);
if((TCFbuffer->EventType == SEND) || (TCFbuffer->EventType == POLLED_SEND))
fprintf(OutFile, ",%s\n", TCFbuffer->DestinationName);
else
fprintf(OutFile, ",%s\n", TCFbuffer->SenderName);
}
/*---------------------------------------------------------------------------*
* ClearLog() *
*---------------------------------------------------------------------------*
* Opens each control file in the log queue and writes the contents to *
* FileName, in either a formatted output (for viewing and printing), tab- *
* delimited, or comma-delimited output (for database importing.) *
*---------------------------------------------------------------------------*
* Parameters: char *FileName - Name and path of output file. If the file *
* exists, no header is printed. If the file does not exist,*
* a header is first printed then the log information is *
* printed. *
* ECF *TCFbuffer - Uninitialized ECF buffer filled with log *
* information on return. *
* FTR *FTRbuffer - Uninitialized FTR buffer filled with file *
* transfer information on return. *
* int Delimiter - Type of delimiter to output in file. *
* Return: none *
*---------------------------------------------------------------------------*/
ClearLog(char *FileName, ECF *TCFbuffer, FTR *FTRbuffer, int Delimiter)
{
int EventHandle; /* Event handle. */
int FileHandle; /* File handles. */
FILE *OutFile; /* Log output file. */
int ErrorCode; /* Return from CAS calls. */
int Header = FALSE; /* Write header to file. */
char action[8]; /* Send, recv, etc. */
char mode[6]; /* Fax or file. */
char status[9]; /* Completed or aborted. */
char buffer[81]; /* Buffer for log fields. */
CAS_DATE *Date; /* CAS date structure. */
CAS_TIME *Time; /* CAS time structure. */
Date = (CAS_DATE *)malloc(sizeof(CAS_DATE));
if(Date == NULL)
CASError(CASNOMEM, TRUE, 0);
Time = (CAS_TIME *)malloc(sizeof(CAS_TIME));
if(Time == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Find the event, open the file and print the header if it is a new file,
otherwise just append the info to what is already there. */
EventHandle = CASFindFirst(ANY_STATUS, SEARCH_FORWARD, LOG_QUEUE);
if(access(FileName,0) == -1) {
/* File doesn't exist - create it and print header. */
if((OutFile = fopen (FileName,"w")) == NULL)
CASError(CASBADLF, TRUE, 0);
if(Delimiter == SPACE_DELIMIT) {
fprintf(OutFile, "\nDate Action Mode Pg/Fi Status ConnectTime To/From\n");
fprintf(OutFile, "-------------------------------------------------------------------------------\n");
}
}
else
/* File exists - open in append mode. */
if((OutFile = fopen (FileName,"a")) == NULL)
CASError(CASBADLF, TRUE, 0);
while(EventHandle > 0) {
/* Fill the TCF buffer with info about the event. */
GetTaskBuffer(EventHandle, LOG_QUEUE, (char *)TCFbuffer, &FileHandle);
close(FileHandle);
CorrectDate(TCFbuffer, Date, Time);
switch(TCFbuffer->EventType) {
case 0: strcpy(action, "Send"); break;
case 1: strcpy(action, "Recv"); break;
case 2: strcpy(action, "Send(P)"); break;
case 4: strcpy(action, "Recv(P)"); break;
default: strcpy(action, "Error");
}
switch(TCFbuffer->TransferType) {
case 0: strcpy(mode, "Fine"); break;
case 1: strcpy(mode, "Std"); break;
case 2: strcpy(mode, "CCP"); break;
default: strcpy(mode, " "); break;
}
switch(TCFbuffer->EventStatus) {
case 0: strcpy(status, "Complete"); break;
case 5: strcpy(status, "Canceled"); break;
default: strcpy(status,"Error"); break;
}
switch(Delimiter) {
/* Print info for space delimited output. */
case SPACE_DELIMIT:
SpaceIt(OutFile, TCFbuffer, Date, Time, action, mode, status);
break;
/* Print info for tab delimited output. */
case TAB_DELIMIT:
TabIt(OutFile, TCFbuffer, Date, Time, action, mode, status);
break;
/* Print info for comma delimited output. */
case COMMA_DELIMIT:
CommaIt(OutFile, TCFbuffer, Date, Time, action, mode, status);
}
EventHandle = CASFindNext(LOG_QUEUE);
}
/* Close the log file and delete events if specified. */
fclose(OutFile);
if(DelLog)
if((ErrorCode = CASDeleteAllFiles(LOG_QUEUE)) < 0)
CASError(CASDELLQ, TRUE, -ErrorCode);
}
/*---------------------------------------------------------------------------*
* Main *
*---------------------------------------------------------------------------*
* The main function calls functions to parse the command line and execute *
* the routines requested with the command line switches. *
*---------------------------------------------------------------------------*
* Return: The DOS exit code is 0 if no errors are encountered, 1 for *
* commandline syntax errors, 2 for CCAM error, and 3 for DOS *
* errors. *
*---------------------------------------------------------------------------*/
main(int argc, char **argv)
{
int result; /* Return value from CAS call. */
int FileType; /* Type of output wanted. */
argc = ParseCommand(argc, argv, SwitchTable, TABLESIZE);
/* If help is wanted, print info and exit (with 0 exit code). */
if(Help || (argc == 1))
CASHelp(DescTable, DESCSIZE, HelpTable, HELPSIZE);
/* Insure that the Resident Scheduler is installed. */
if((result = CASGetInstalledState()) != INSTALLED) {
if( result == NOTiOK )
CASError(CASNOHWO, TRUE, 0);
else
CASError(CASNOHWN, TRUE, 0);
}
/* Redirect stdout to a file. */
if(RedirOut) {
if((ccout = fopen("OUTPUT.CC", "w")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
if(-1 == dup2(fileno(ccout), 1))
CASError(CASBADREDIR, TRUE, 0);
}
/* Check to make sure that a (one only) path name was specified. */
if(argc < 2)
CASError(CASARGPATH, TRUE, 0);
else if(argc > 2)
CASError(CASARGMULTPATH, TRUE, 0);
/* Get buffer for Task information. */
TCFbuffer = (ECF *)malloc(sizeof(ECF));
if(TCFbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get buffer for File Transfer information. */
FTRbuffer = (FTR *)malloc(sizeof(FTR));
if(FTRbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Make sure that only one switch can be set! */
if(!Tab && !Comma)
FileType = SPACE_DELIMIT;
else if(Tab)
FileType = TAB_DELIMIT;
else
FileType = COMMA_DELIMIT;
/* Point to the filename and print it. */
argv++;
ClearLog(*argv, TCFbuffer, FTRbuffer, FileType);
exit(0);
}